<!-- html -->
<template>
	<view class="container">
		<!-- 通知消息 -->
		<view class="notice" @click="go_notice_detail">
			<view>
				<image src="https://community.chuangxiangdianli.com/images/neighborimg/market/notice.png" mode=""></image>
			</view>
			<view>
				<view>
					通知消息
				</view>
				<!-- <view>
					提现成功，请核对信息
				</view> -->
			</view>
			<view v-if="Number(no_reade.systemNotice)">
				<text>{{no_reade.systemNotice}}</text>
			</view>
		</view>
		<!-- 其他消息 -->
		<view class="other-notice" v-if="list.length>0">
			<template v-for="item in list">
				<view class="other-item" 
					:key="item.id"
					@longpress="del_news(item)"
					@click="go_detail(item)">
					<view class="avator">
						<image :src="item.user.avatar" mode=""></image>
					</view>
					<!-- 不同的消息有区别的地方 -->
					<view 
						class="detail coll" 
						v-if="item.type==1"
						>
						<view class="name">
							{{item.user.username}}
						</view>
						<view class="instroduce">
							{{item.msg}}
						</view>
						<view class="time">
							{{item.created_at}}
						</view>
					</view>
					<view class="detail evaluate" v-if="item.type==3">
						<view class="name">
							{{item.user.username}}
						</view>
						<view>
							点击查看订单评价
						</view>
						<view>
							<text>{{item.msg}}</text>
							<text>{{item.created_at}}</text>
						</view>
					</view>
					<view class="detail evaluate message" v-if="item.type==2">
						<view class="name">
							{{item.user.username}}
						</view>
						<view>
							长按可删除通知消息，点击跳转
							到发布详情页
						</view>
						<view>
							<text>{{item.msg}}</text>
							<text>{{item.created_at}}</text>
						</view>
					</view>
					<view >
						<template v-show="item.goods">
							<image v-show="item.goods.goods_images.length>0" 
							:src="item.goods.goods_images[0]" mode=""></image>
						</template>
					</view>
				</view>
			</template>
		</view>
		<view class="nodata" v-else>
			<image 
			src="https://community.chuangxiangdianli.com/images/empty/nomessage.png" mode=""></image>
		</view>
		<!-- 底部的tabbar -->
		<market-tab-bar :activeIndex="bottom_tab_bar_index" />
		<u-loadmore :status="status" />
	</view>
</template>
<!-- js -->
<script>
	// 引入封装的请求
	import request from '@/utils/request.js'	
	import MarketTabBar from '../../common/MarketTabBar/index.vue'
	export default {
		components:{
			MarketTabBar
		},
		data() {
			return {
				// 底部导航索引
				bottom_tab_bar_index:'3',
				// 商品列表
				list:[],
				// 当前页码
				pageNo:1,
				// 列表个数 
				limit:10,
				// 是否正在请求数据
				is_loading:false,
				// 是否请求完数据
				is_bottom:false,
				// 底部正在加载中
				status: 'loadmore',
				// 未读的消息统计
				no_reade:{
					// 系统通知
					systemNotice:null,
					// 用户信息
					userNotice:null
				}
			}
		},
		computed: {
			
		},
		watch: {
			
		},
		onLoad() {
			this.get_news_list()
		},
		onShow() {
			// 获取未读的消息
			this.get_no_read()
		},
		// 页面底部加载
		onReachBottom(){
			let that = this
			this.status = 'loading';
			// console.log(11111)
			if(that.status = 'nomore' || that.is_loading){
				return false
			}
			this.pageNo++
			setTimeout(() => {
				that.get_news_list(true)
			}, 1000)
		},
		// 自定义返回逻辑
		onBackPress() {
			uni.navigateBack({
				url:'/neighbor/index'
			})
			return true //表示禁止默认返回
		},
		methods: {
			// 前往通知消息的详情
			go_notice_detail(){
				uni.navigateTo({
					url: '../noticeVews/index'
				});
			},
			// 点击消息跳转
			go_detail(item){
				if(item.type==1 || item.type == 2){
					let goods_id = item.goods.id
					uni.navigateTo({
						url:'../goodsInfo/index?id='+goods_id
					})
					return false
				}
				uni.navigateTo({
					url:'../order/orderComment?id='+item.order_id+'&type=2'
				})
			},
			// 删除消息
			del_news(item){
				// console.log(item.id)
				let that = this
				uni.showModal({
				    title: '提示',
				    content: '确定删除当前消息吗',
				    success: function (res) {
				        if (res.confirm) {
							this.$mrequest2({
								url:'Mini/circle/flea/destroyNotice/'+item.id,
								method:'DELETE',
								data:{
									id:item.id
								}
							}).then(res=>{
								console.log(res)
								if(res.code==200){
									that.get_news_list()
								}
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			// 获取未读的消息数量 
			get_no_read(){
				let that = this
				request.get('Mini/circle/flea/getMyNotReadNotice').then(res=>{
					// console.log(res)
					if(res.code==200){
						that.no_reade = res.data
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			// 获取消息列表
			get_news_list(turn){
				let that = this
				that.is_loading = true
				request.get('Mini/circle/flea/fleaNotice',{
					page:that.pageNo,
					limit:that.limit,
				}).then(res=>{
					// console.log('首页数据', res)
					that.is_loading = false
					if (res.code==200) {
						if(turn){
							if(res.data.data.length>0){
								that.list = [
									...that.list,
									...res.data.data
								]
							}
						}else{
							that.list = res.data.data
						}
						if(res.data.count==that.list.length){
							// that.is_boottom = true
							that.status = 'nomore';
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				})
			},
			// 改变底部tabbar
			chang_bottom_tab(i){
				this.bottom_tab_bar_index=''+i
				// console.log(this.bottom_tab_bar_index)
			}
		}
	}
</script>
<!-- css -->
<style lang="scss" scoped>
	.container{
		width: 100vw;
		height: auto!important;
		box-sizing: border-box;
		background-color: #F3F5F8;
		padding-bottom: 100rpx;
		.notice{
			width: 100%;
			height: 210rpx;
			padding-left: 21rpx;
			padding-right: 42rpx;
			display: flex;
			align-items: center;
			&>view:nth-child(1){
				width: 100rpx;
				height: 100rpx;
				margin-right: 50rpx;
				&>image{
					width: 100%;
					height: 100%;
				}
			}
			&>view:nth-child(2){
				&>view:nth-child(1){
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
				&>view:nth-child(2){
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
			&>view:nth-child(3){
				margin-left: auto;
				min-width: 29rpx;
				min-height: 29rpx;
				background: #FF1212;
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
		}
		.nodata{
			width: 100%;
			display: flex;
			justify-content: center;
			&>image{
				width: 400rpx;
				height: 400rpx;
			}
		}
		.other-notice{
			width: 100%;
			padding-left: 22rpx;
			padding-right: 24rpx;
			box-sizing: border-box;
			background-color: #F3F5F8;
			.other-item{
				margin-top: 33rpx;
				display: flex;
				align-items: flex-start;
				justify-content:space-between;
				.avator{
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					overflow: hidden;
					box-sizing: border-box;
					&>image{
						width: 100%;
						height: 100%;
					}
				}
				.detail{
					width: 373rpx;
					overflow: hidden;
					&>view:nth-child(1){
						width: 100%;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #333333;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
						margin-bottom: 35rpx;
					}
					&.coll{
						&>view:nth-child(2),
						&>view:nth-child(3){
							font-size: 24rpx;
							font-family: Hiragino Sans GB;
							font-weight: bold;
							color: #999999;
						}
						.instroduce{
							margin-bottom: 20rpx;
						}
					}
					&.evaluate{
						&>view:nth-child(1){
							margin-bottom: 22rpx;
						}
						&>view:nth-child(2){
							font-size: 26rpx;
							font-family: Hiragino Sans GB;
							font-weight: bold;
							color: #333333;
							margin-bottom: 15rpx;
						}
						&>view:nth-child(3){
							font-size: 24rpx;
							font-family: Hiragino Sans GB;
							color: #999999;
							&>text:nth-child(1){
								margin-right: 30rpx;
							}
						}
					}
				}
				&>view:last-child{
					width: 140rpx;
					height: 152rpx;
					border-radius: 10px;
					&>image{
						width: 100%;
						height: 100%;
					}
				}
			}
		}
	}
</style>
